package com.jiaai.cloud.base.inceptor;

import com.jiaai.cloud.base.entity.ErrorCode;
import com.jiaai.cloud.base.exception.LoginException;
import com.jiaai.cloud.base.util.HttpHeaderUtils;
import com.jiaai.cloud.wx.entity.TEmp;
import com.jiaai.cloud.wx.service.ITEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/9/1.
 */
@Component
public class FrontLoginInteceptor extends HandlerInterceptorAdapter {
    @Autowired
    private ITEmpService itEmpService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       TEmp tEmp = itEmpService.selectById(HttpHeaderUtils.getUserId());

        if (tEmp == null){
            throw new LoginException("员工未登录", ErrorCode.NOT_LOGIN, "");
        }
        return true;
    }
}
